package com.example.foobar.controller;

import com.example.foobar.business.service.DaDataAnalysisService;
import com.example.foobar.business.service.impl.DaNewCommerCountServiceImpl;
import com.example.foobar.dto.DABaseDTO;
import com.example.foobar.entity.DaDataAnalysis;
import com.example.foobar.dao.service.DaDataAnalysisDaoService;
import com.example.foobar.vo.AnalysisData;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DaDataAnalysisPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * 新增用户数记录 控制器
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@RestController
@RequestMapping("/daDataAnalysis")
@Module("daDataAnalysisController")
@Api(value = "新增用户数记录API", tags = {"新增用户数记录"})
public class DaDataAnalysisController extends BaseController {

    @Autowired
    private DaDataAnalysisService daDataAnalysisService;

    /**
     * 添加新增用户数记录
     */
    @PostMapping("/add")
    @OperationLog(name = "添加新增用户数记录", type = OperationLogType.ADD)
    @ApiOperation(value = "添加新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> addDaDataAnalysis(@Validated(Add.class) @RequestBody DaDataAnalysis daDataAnalysis) throws Exception {
        boolean flag = daDataAnalysisService.saveDaDataAnalysis(daDataAnalysis);
        return ApiResult.result(flag);
    }

    /**
     * 修改新增用户数记录
     */
    @PostMapping("/update")
    @OperationLog(name = "修改新增用户数记录", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> updateDaDataAnalysis(@Validated(Update.class) @RequestBody DaDataAnalysis daDataAnalysis) throws Exception {
        boolean flag = daDataAnalysisService.updateDaDataAnalysis(daDataAnalysis);
        return ApiResult.result(flag);
    }

    /**
     * 删除新增用户数记录
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除新增用户数记录", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除新增用户数记录", response = ApiResult.class)
    public ApiResult<Boolean> deleteDaDataAnalysis(@PathVariable("id") Long id) throws Exception {
        boolean flag = daDataAnalysisService.deleteDaDataAnalysis(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取新增用户数记录详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "新增用户数记录详情", type = OperationLogType.INFO)
    @ApiOperation(value = "新增用户数记录详情", response = DaDataAnalysis.class)
    public ApiResult<DaDataAnalysis> getDaDataAnalysis(@PathVariable("id") Long id) throws Exception {
        DaDataAnalysis daDataAnalysis = daDataAnalysisService.getById(id);
        return ApiResult.ok(daDataAnalysis);
    }


    /**
     * 获取留存数据
     */
    @GetMapping("/getAnalysisData")
    @OperationLog(name = "查询留存数据", type = OperationLogType.PAGE)
    @ApiOperation(value = "查询留存数据", response = DaDataAnalysis.class)
    public ApiResult<Paging<AnalysisData>> getAnalysisData(String date, String uniacid) throws Exception {
        Paging<AnalysisData> paging = daDataAnalysisService.getDaDataAnalysisPageList(date, uniacid);
        return ApiResult.ok(paging);
    }

}

